package org.xiaojun.loginDemo.service.impl;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.xiaojun.loginDemo.pojo.Employee;
import org.xiaojun.loginDemo.mapper.EmployeeMapper;
import org.xiaojun.loginDemo.service.IEmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xj
 * @since 2021-08-07
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public String saveEmployee(Employee employee) {

        String msg = null;

        if (StringUtils.isBlank(employee.getUserName()) || Objects.isNull(employee.getAge())){
            msg = "姓名或年龄不能为空";
            return msg;
        }

        if (!this.save(employee)){
            msg = "添加失败";
            return msg;
        }
        return null;
    }
}
